Procedural Guidance
1. The Mockery Standard
- Base Class: All tests must extend
Tests\Unit\TestCase. - Config Mocking: Use
$this->mockConfig->shouldReceive('get')->with('key')->andReturn(...). - Repo Mocking: Mock repositories to return Entities, never raw arrays (unless it's a legacy repo).
2. The Assertion Protocol
- ServiceResponse: Use helper methods
$this->assertServiceSuccess($response)and$this->assertServiceFailure($response). - Transactions: Ensure the Service test mocks
$db->beginTransaction(),commit(), androllBack().
3. Integration vs Unit
- Unit: Default. Mock everything. Place in
tests/Unit/Services/. - Integration: Only if DB interactions are complex. Must use the
try { $db->beginTransaction(); ... } finally { $db->rollBack(); }pattern found intests/Integration/.
4. Output Format
Provide the full, drop-in PHP file ending in Test.php.